<template>
  <div class="wrap">
    <template>
      <el-tabs v-model="params.curTab" @tab-click="setCurTab">
        <el-tab-pane name="BaseParameters" :label="$t('message.InsulationCoverFrameToolDlg.baseParameters')">
          <div>
            <query-list
                    v-model="params.skins"
                    :description="$t('message.InsulationCoverFrameToolDlg.skins')"
                    :active="params.queryListActiveMap.skins"
                    @switchQuery="switchQuery('skins')"
                    :tipMsg="$t('message.InsulationCoverFrameToolDlg.skins')">
            </query-list>
          </div>
          <div>
            <query-list
                    v-model="params.frames"
                    :description="$t('message.InsulationCoverFrameToolDlg.framePosition')"
                    :active="params.queryListActiveMap.frames"
                    @switchQuery="switchQuery('frames')"
                    :tipMsg="$t('message.InsulationCoverFrameToolDlg.framePosition')">
            </query-list>
          </div>
          <div>
            <query-list
                    v-model="params.stringers"
                    description="$t('message.InsulationCoverFrameToolDlg.stringerPosition')"
                    :active="params.queryListActiveMap.stringers"
                    @switchQuery="switchQuery('stringers')"
                    :tipMsg="$t('message.InsulationCoverFrameToolDlg.stringerPosition')">
            </query-list>
          </div>

          <el-checkbox v-model="params.bReinforceFrame">{{ $t('message.InsulationCoverFrameToolDlg.reinforceFrame') }}</el-checkbox>
          <div v-if = "params.bReinforceFrame" class="d-flex align-items-center">
            <query-list
              v-model="params.reinforcedStringers"
              description="$t('message.InsulationCoverFrameToolDlg.reinforcedStringer')"
              :active="params.queryListActiveMap.reinforcedStringers"
              @switchQuery="switchQuery('reinforcedStringers')"
              :tipMsg="$t('message.InsulationCoverFrameToolDlg.reinforcedStringer')">
            </query-list>
          </div>
          <div class="d-flex align-items-center">
            <label class="el-form-item__label">{{ $t('message.InsulationCoverFrameToolDlg.frameType') }}:</label>
            <el-select v-model="params.frameType">
              <el-option
                v-for="item in params.frameTypeList"
                :key="item.value"
                :label="item.text"
                :value="item.value">
              </el-option>
            </el-select>
          </div>
          <div class="d-flex align-items-center">
            <label class="el-form-item__label">{{ $t('message.InsulationCoverFrameToolDlg.course') }}:</label>
            <el-select v-model="params.courseNo">
              <el-option
                v-for="item in params.courseOptions"
                :key="item.value"
                :label="item.text"
                :value="item.value">
              </el-option>
            </el-select>
          </div>

        </el-tab-pane>
        <el-tab-pane name="Params3D" :label="$t('message.InsulationCoverFrameToolDlg.params3D')">
          <el-image class="url-style"
                    :src="url('coverframeparam.png')"
                    fit="fill">
          </el-image>
          <!--   实体厚度       -->
          <div class="d-flex align-items-center">
            <label class="label-style">{{ $t('message.InsulationCoverFrameToolDlg.solidThickness') }}：</label>
            <el-input id="solidThickness"
                      v-model.number="params.solidThickness"
                      type = "number"
                      min = 0
                      step = "1"/>
            <label class="label">mm</label>
          </div>
          <!--   框缘宽度       -->
          <div class="d-flex align-items-center">
            <label class="label-style">{{ $t('message.InsulationCoverFrameToolDlg.frameEdgeWidth') }}：</label>
            <el-input id="frameEdgeWidth"
                      v-model.number="params.frameEdgeWidth"
                      type = "number"
                      step = "1"/>
            <label class="label">mm</label>
          </div>
          <!--   长桁高度，当时全高度框时，无此高度      -->
          <div v-if = "params.frameType === 1" class="d-flex align-items-center">
            <label class="label-style">{{ $t('message.InsulationCoverFrameToolDlg.stringerHeight') }}：</label>
            <el-input id="stringerHeight"
                      v-model.number="params.stringerHeight"
                      type = "number"
                      min = 0
                      step = "1"/>
            <label class="label">mm</label>
          </div>
          <!--   标准框高       -->
          <div class="d-flex align-items-center">
            <label class="label-style">{{ $t('message.InsulationCoverFrameToolDlg.standardFrameHeight') }}：</label>
            <el-input id="standardFrameHeight"
                      v-model.number="params.standardFrameHeight"
                      type = "number"
                      min = 0
                      step = "1"/>
            <label class="label">mm</label>
          </div>
          <!--   蒙皮顺偏       -->
          <div class="d-flex align-items-center">
            <label class="label-style">{{ $t('message.InsulationCoverFrameToolDlg.skinPositiveOffsetValue') }}：</label>
            <el-input id="skinOffsetP"
                      v-model.number="params.skinOffsetP"
                      type = "number"
                      min = 0
                      step = "1"/>
            <label class="label">mm</label>
          </div>
          <!--   蒙皮逆偏       -->
          <div class="d-flex align-items-center">
            <label class="label-style">{{ $t('message.InsulationCoverFrameToolDlg.skinNegativeOffsetValue') }}：</label>
            <el-input id="skinOffsetN"
                      v-model.number="params.skinOffsetN"
                      type = "number"
                      min = 0
                      step = "1"/>
            <label class="label">mm</label>
          </div>
          <!--   内饰顺偏       -->
          <div class="d-flex align-items-center">
            <label class="label-style">{{ $t('message.InsulationCoverFrameToolDlg.innerPositiveOffsetValue') }}：</label>
            <el-input id="innerOffsetP"
                      v-model.number="params.innerOffsetP"
                      type = "number"
                      min = 0
                      step = "1"/>
            <label class="label">mm</label>
          </div>
          <!--   内饰逆偏       -->
          <div class="d-flex align-items-center">
            <label class="label-style">{{ $t('message.InsulationCoverFrameToolDlg.innerNegativeOffsetValue') }}：</label>
            <el-input id="innerOffsetN"
                      v-model.number="params.innerOffsetN"
                      type = "number"
                      min = 0
                      step = "1"/>
            <label class="label">mm</label>
          </div>

          <template v-if = "params.bReinforceFrame" class="d-flex align-items-center">
            <!--   蒙皮顺偏       -->
            <div class="d-flex align-items-center">
              <label class="label-style">{{ $t('message.InsulationCoverFrameToolDlg.skinPositiveOffsetValueS') }}：</label>
              <el-input id="skinOffsetPS"
                        v-model.number="params.skinOffsetPS"
                        type = "number"
                        min = 0
                        step = "1"/>
              <label class="label">mm</label>
            </div>
            <!--   蒙皮逆偏       -->
            <div class="d-flex align-items-center">
              <label class="label-style">{{ $t('message.InsulationCoverFrameToolDlg.skinNegativeOffsetValueS') }}：</label>
              <el-input id="skinOffsetNS"
                        v-model.number="params.skinOffsetNS"
                        type = "number"
                        min = 0
                        step = "1"/>
              <label class="label">mm</label>
            </div>
            <!--   内饰顺偏       -->
            <div class="d-flex align-items-center">
              <label class="label-style">{{ $t('message.InsulationCoverFrameToolDlg.innerPositiveOffsetValueS') }}：</label>
              <el-input id="innerOffsetPS"
                        v-model.number="params.innerOffsetPS"
                        type = "number"
                        min = 0
                        step = "1"/>
              <label class="label">mm</label>
            </div>
            <!--   内饰逆偏       -->
            <div class="d-flex align-items-center">
              <label class="label-style">{{ $t('message.InsulationCoverFrameToolDlg.innerNegativeOffsetValueS') }}：</label>
              <el-input id="innerOffsetNS"
                        v-model.number="params.innerOffsetNS"
                        type = "number"
                        min = 0
                        step = "1"/>
              <label class="label">mm</label>
            </div>

            <!--   标准框高       -->
            <div class="d-flex align-items-center">
              <label class="label-style">{{ $t('message.InsulationCoverFrameToolDlg.standardFrameHeightS') }}：</label>
              <el-input id="standardFrameHeightS"
                        v-model.number="params.standardFrameHeightS"
                        type = "number"
                        min = 0
                        step = "1"/>
              <label class="label">mm</label>
            </div>
          </template>
        </el-tab-pane>
        <el-tab-pane name="Params2D" :label="$t('message.InsulationCoverFrameToolDlg.params2D')">
          <div>
            <el-image class="url-style"
                      :src="url('coverframe2d.png')"
                      fit="fill">
            </el-image>
          </div>
          <div class="d-flex align-items-center">
            <label class="label-style">{{ $t('message.InsulationCoverFrameToolDlg.horizontalWidth') }}：</label>
            <el-input id="hWidth"
                      v-model.number="params.horizontalWidth"
                      type = "number"
                      min = 0
                      step = "1"/>
            <label class="label">mm</label>
          </div>
          <div class="d-flex align-items-center">
            <label class="label-style">{{ $t('message.InsulationCoverFrameToolDlg.verticalWidth') }}：</label>
            <el-input id="vWidth"
                      v-model.number="params.verticalWidth"
                      type = "number"
                      min = 0
                      step = "1"/>
            <label class="label">mm</label>
          </div>
          <div class="d-flex align-items-center">
            <label class="label-style">{{ $t('message.InsulationCoverFrameToolDlg.zoomRatio') }}：</label>
            <el-input id="zoom"
                      v-model.number="params.zoomRatio"
                      type = "number"
                      min = 0
                      step = "1"/>
          </div>
          <div class="d-flex align-items-center">
            <label class="label-style">安装孔边距（dM）:</label>
            <el-input id="dM"
                      v-model.number="params.dM"
                      type = "number"
                      min = 0
                      step = "1"/>
            <label class="label">mm</label>
          </div>
          <div class="d-flex align-items-center">
            <label class="label-style">安装孔离蒙皮距离（RIS）:</label>
            <el-input id="RIS"
                      v-model.number="params.RIS"
                      type = "number"
                      min = 0
                      step = "1"/>
            <label class="label">mm</label>
          </div>
          <div class="d-flex align-items-center">
            <label class="label-style">转折补偿经验值（k）:</label>
            <el-input id="k"
                      v-model.number="params.k"
                      type = "number"
                      min = 0
                      step = "1"/>
            <label class="label">mm</label>
          </div>
          <div class="d-flex align-items-center">
            <label class="label-style">包覆膜比芯体加宽的尺寸（dBx）:</label>
            <el-input id="dBx"
                      v-model.number="params.dBx"
                      type = "number"
                      min = 0
                      step = "1"/>
            <label class="label">mm</label>
          </div>
        </el-tab-pane>
        <el-tab-pane name="OtherParams" :label="$t('message.InsulationCoverFrameToolDlg.otherParams')">
          <!--          开孔参数-->
          <div>
            <div class="operation-border" >
              <div class="label-style">
                <p><b>{{ $t('message.InsulationCoverFrameToolDlg.holeParameters') }}</b></p>
              </div>

              <div class="d-flex align-items-center">
                <label class="label-style">{{ $t('message.InsulationCoverFrameToolDlg.holeAxisOffset') }}：</label>
                <el-input id="holeOffset"
                          v-model.number="params.holeAxisOffset"
                          type = "number"
                          min = 0
                          step = "1"/>
                <label class="label">mm</label>
              </div>

              <div>
                <label class="label-style">{{ $t('message.InsulationCoverFrameToolDlg.installHoleList') }}</label>
              </div>
              <el-table ref="sectionList"
                        :data="params.installHoleInfoList"
                        highlight-current-row
                        @current-change="handleCurrentChange"
                        tooltip-effect="dark"
                        style="width: 100%;margin-top: 5px"
                        border size="small">
                <el-table-column prop="index"
                                 :label="$t('message.InsulationCoverFrameToolDlg.number')"
                                 min-width="30">
                  <template v-slot="scope">
                    <label class="label">{{scope.row.holeIndex + 1}}</label>
                  </template>
                </el-table-column>
                <el-table-column prop="index"
                                 :label="$t('message.InsulationCoverFrameToolDlg.name')"
                                 min-width="80">
                  <template v-slot="scope">
                    <label class="label">{{scope.row.holeName}}</label>
                  </template>
                </el-table-column>
                <el-table-column prop="holeSymmetry"
                                 :label="$t('message.InsulationCoverFrameToolDlg.installHoleSymmetry')"
                                 min-width="50">
                  <template v-slot="scope">
                    <label class="label">{{ scope.row.holeSymmetryName}}</label>
                  </template>
                </el-table-column>
                <el-table-column prop="holeType"
                                 :label="$t('message.InsulationCoverFrameToolDlg.installHoleType')"
                                 min-width="40">
                  <template v-slot="scope">
                    <label class="label">{{ scope.row.holeType }}</label>
                  </template>
                </el-table-column>
              </el-table>
              <div class="button-style">
                <el-button type="primary" size="small" :disabled="false" @click="addHoleData()">
                  {{ $t('message.InsulationCoverFrameToolDlg.add') }}
                </el-button>
                <el-button type="primary" size="small" :disabled="buttonDisabled()" @click="editHoleData()">
                  {{ $t('message.InsulationCoverFrameToolDlg.edit') }}
                </el-button>
                <el-button type="primary" size="small" :disabled="buttonDisabled()" @click="deleteHoleData()">
                  {{ $t('message.InsulationCoverFrameToolDlg.delete') }}
                </el-button>
              </div>
            </div>
            <div class="operation-border" v-if="isHoleEdit">
              <query-list
                v-model="params.installHolePointList"
                :description="$t('message.InsulationCoverFrameToolDlg.installHolePointList')"
                :active="params.queryListActiveMap.installHolePointList"
                @switchQuery="switchQuery('installHolePointList')"
                :tipMsg="$t('message.InsulationCoverFrameToolDlg.installHolePointList')">
              </query-list>
              <div class="d-flex align-items-center">
                <label class="el-form-item__label">{{ $t('message.InsulationCoverFrameToolDlg.holeType') }}:</label>
                <el-select v-model="params.holeType">
                  <el-option
                    v-for="item in params.holeTypeList"
                    :key="item.value"
                    :label="item.text"
                    :value="item.value">
                  </el-option>
                </el-select>
              </div>
              <el-radio-group v-model="params.holeSymmetry">
                <el-radio label="0">{{$t('message.InsulationCoverFrameToolDlg.symmetry')}}</el-radio>
                <el-radio label="1">{{$t('message.InsulationCoverFrameToolDlg.left')}}</el-radio>
                <el-radio label="2">{{$t('message.InsulationCoverFrameToolDlg.right')}}</el-radio>
              </el-radio-group>
              <div class="button-style">
                <el-button type="primary" size="small" :disabled="false" @click="saveHoleData()">
                  {{ $t('message.InsulationCoverFrameToolDlg.save') }}
                </el-button>
                <el-button type="primary" size="small" :disabled="false" @click="cancelHoleData()">
                  {{ $t('message.InsulationCoverFrameToolDlg.cancel') }}
                </el-button>
              </div>
              <el-image class="url-style2"
                        :src="url('holeType.png')"
                        fit="fill">
              </el-image>
            </div>

          </div>
          <!--          开叉参数-->
          <div class="operation-border">
            <div class="label-style">
              <p><b>{{ $t('message.InsulationCoverFrameToolDlg.forkParameters') }}</b></p>
            </div>
            <div>
              <query-list
                      v-model="params.forkLineList"
                      :description="$t('message.InsulationCoverFrameToolDlg.forkCenterLine')"
                      :active="params.queryListActiveMap.forkLineList"
                      @switchQuery="switchQuery('forkLineList')"
                      :tipMsg="$t('message.InsulationCoverFrameToolDlg.forkCenterLine')">
              </query-list>
            </div>

<!--            <div class="d-flex align-items-center">-->
<!--              <label class="el-form-item__label">{{ $t('message.InsulationCoverFrameToolDlg.forkType') }}:</label>-->
<!--              <el-select v-model="params.forkType">-->
<!--                <el-option-->
<!--                        v-for="item in params.forkTypeList"-->
<!--                        :key="item.value"-->
<!--                        :label="item.text"-->
<!--                        :value="item.value">-->
<!--                </el-option>-->
<!--              </el-select>-->
<!--            </div>-->
            <div class="d-flex align-items-center">
              <label class="label-style">{{ $t('message.InsulationCoverFrameToolDlg.centerLineDistance') }}：</label>
              <el-input v-model.number="params.centerLineDistance"
                        type = "number"
                        min = 0
                        step = "1"/>
            </div>
            <el-image class="url-style2"
                      :src="url('jagcenterline.png')"
                      fit="fill">
            </el-image>
          </div>
        </el-tab-pane>
      </el-tabs>
    </template>
    <!--    确认和关闭-->
    <div class="btn">
      <el-button
              type="primary"
              size="small"
              @click="confirm">
        {{ $t('message.common.confirm') }}
      </el-button>
      <el-button
              size="small"
              @click="cancel">
        {{ $t('message.common.cancel') }}
      </el-button>
    </div>
  </div>
</template>
<script>
  import {ElementType, GeomType} from "../../../modeling/TypeDefine";
  import {InsulationCoverFrameToolCmd} from "../../../command/InsulationCoverFrameToolCommand";
  import DialogMixin from "../DialogMixin";
  import {getCommonPic} from "../../js/util/GetCommonPic";

  export default {
    mixins: [DialogMixin],
    name: 'HeatAndSoundInsulationDlg',
    data() {
      return {
        tabOptions: ["BaseParameters", "Params3D","Params2D","OtherParams"],
        params: {
          curTab: "BaseParameters",
          skins: [],
          frames: [],
          stringers: [],
          bReinforceFrame:false,
          reinforcedStringers: [],
          frameType:1,
          frameTypeList:[{text:"标准隔框",value:1},{text:"全高度框",value:2}],

          horizontalWidth: 20,
          verticalWidth: 30,
          zoomRatio: 1.035,
          stringerCount: 5,

          allQueueStringerPlane:[],         //所有长桁站位对象，已经进行排序
          stringerDisList:[],               //所有的长桁距离列表，包括中间夹着的

          bFrameEdgeSymmetry:false, //框缘是否对称，即框的形状为工字钢还是Z字钢
          //CATIA中生成包框的相关参数
          skinOffsetP:5,
          skinOffsetN:5,
          innerOffsetP:5,
          innerOffsetN:5,
          stringerHeight:30,
          standardFrameHeight:90,
          solidThickness:30,
          frameEdgeWidth:20,
          dM:40,
          RIS:60,
          k:60,
          dBx:25.4,

          //加强框参数
          skinOffsetPS:10,
          skinOffsetNS:10,
          innerOffsetPS:10,
          innerOffsetNS:10,
          standardFrameHeightS:120,
          nNoS:0,   //加强长桁在所有长桁中的序号

          //开孔参数
          holeTypeList:[{text:"1",value:1},{text:"2",value:2}],
          holeAxisOffset:40,
          installHolePointList:[],
          installHoleInfoList:[],
          holeSelectInfo:{},
          holeSymmetry:"0",//对称0，左侧1，右侧2
          holeSymmetryName:"对称",
          holeType:1,
          holeIndex:0,
          holeName:"",

          //开叉参数
          forkType:2,
          forkTypeList:[{text:"1",value:1},{text:"2",value:2}],
          forkLineList:[],
          centerLineDistance: 10,


          courseOptions: [{text:"X轴",value:11},
            {text:"-X轴",value:12},
            {text:"Y轴",value:21},
            {text:"-Y轴",value:22},
            {text:"Z轴",value:31},
            {text:"-Z轴",value:32}],
          courseNo:11,
          queryListActiveMap: {
            skins: 1,
            frames: 0,
            stringers: 0,
            reinforcedStringers: 0,
            installHolePointList:0,
            forkLineList:0,
          }

        },
        isHoleEdit:false,
        editType:-1,   //添加还是新建，添加1，编辑0,删除-1
      }
    },
    mounted() {
      InsulationCoverFrameToolCmd.init(700,400,500,async () => {
        if(true){
          //this.params.skins = await InsulationCoverFrameToolCmd.getElementByFeatureName(["扫描曲面1"],0);
          //this.params.frames = await InsulationCoverFrameToolCmd.getElementByFeatureName(["导入基准面1"]);
          //this.params.stringers = await InsulationCoverFrameToolCmd.getElementByFeatureName(["导入基准面3","导入基准面11"]);
          //this.params.reinforcedStringers = await InsulationCoverFrameToolCmd.getElementByFeatureName(["导入基准面5"]);

          //Test
          //this.params.forkLineList = await InsulationCoverFrameToolCmd.getElementByFeatureName(["草图801"],0);

          this.params.courseOptions = [{text:"X轴",value:11},
            {text:"-X轴",value:12},
            {text:"Y轴",value:21},
            {text:"-Y轴",value:22},
            {text:"Z轴",value:31},
            {text:"-Z轴",value:32}];
          this.params.courseNo = 11;
          this.params.bReinforceFrame = true;
        }

        //InsulationCoverFrameToolCmd.setSelectType([ElementType.FACE, ElementType.SURFACE,ElementType.VERTEX,ElementType.EDGE,ElementType.DATUMLINE]);
        InsulationCoverFrameToolCmd.handlePickElement(pickResult => {
          pickResult?.element?.forEach(data => {
            let element = data.element;
            if (!element) {
              return;
            }
            let activeKey = "skins";
            for (const key in this.params.queryListActiveMap) {
              if (this.params.queryListActiveMap[key] === 1) {
                activeKey = key;
              }
            }
            if (["frames", "stringers", "reinforcedStringers"].includes(activeKey) &&
              (element.type === ElementType.DATUMPLANE || (element.type === ElementType.FACE && element.params?.surfaceType === GeomType.PLANE))) {
              if (activeKey === "frames") {
                //如果选取了为框站位面
                this.params[activeKey] = InsulationCoverFrameToolCmd.filterRepeatElement(this.params[activeKey], element, true);
                //确定改变航向的可选择项
                this.modifyCourse(element);
                this.switchQuery("stringers");
              } else if(activeKey === "stringers") {
                this.params[activeKey] = InsulationCoverFrameToolCmd.filterRepeatElement(this.params[activeKey], element);
              }else if(activeKey === "reinforcedStringers") {
                this.params[activeKey] = InsulationCoverFrameToolCmd.filterRepeatElement(this.params[activeKey], element, true);
              }
            } else if (activeKey === "skins" && element.type === ElementType.FACE) {
              this.params[activeKey] = InsulationCoverFrameToolCmd.filterRepeatElement(this.params[activeKey], element, true);
              this.switchQuery("frames");
            } else if (activeKey === "installHolePointList" &&
              (element.type === ElementType.VERTEX
                || element.type === ElementType.POINT
                || element.type === ElementType.POINTONCURVE
                || element.type === ElementType.DATUMPOINT
                || element.type === ElementType.ORIGINPOINT)) {
              this.params.installHolePointList = InsulationCoverFrameToolCmd.filterRepeatElement(this.params.installHolePointList, element);
              //this.params.installHolePointList = [element];
            } else if (activeKey === "forkLineList" &&
              (element.type === ElementType.EDGE
                || element.type === ElementType.CURVE
                || element.type === ElementType.SECTIONLINE)) {
              this.params.forkLineList = InsulationCoverFrameToolCmd.filterRepeatElement(this.params.forkLineList, element);
            }
          })
        })
      });
    },
    methods: {
      changePluginContainerHeight() {
        InsulationCoverFrameToolCmd.changePluginContainerHeight({minWidth: this.$el.clientWidth, maxHeight: this.$el.clientHeight,width:400})
      },
      url(imgName) {
        return getCommonPic(imgName, "heatSoundInsulation");
      },
      switchQuery(name) {
        for (const key in this.params.queryListActiveMap) {
          this.params.queryListActiveMap[key] = key === name ? 1 : 0;
        }
        if (name === "skins") {
          InsulationCoverFrameToolCmd.setSelectType([ElementType.FACE, ElementType.SURFACE]);
        } else if (name === "installHolePointList") {
          InsulationCoverFrameToolCmd.setSelectType([ElementType.VERTEX, ElementType.POINT, ElementType.POINTONCURVE, ElementType.DATUMPOINT,ElementType.ORIGINPOINT]);
        } else if (name === "forkLineList"){
          InsulationCoverFrameToolCmd.setSelectType([ElementType.EDGE, ElementType.CURVE, ElementType.SECTIONLINE]);
        } else {
          InsulationCoverFrameToolCmd.setSelectType([ElementType.DATUMPLANE, ElementType.WORKPLANE,ElementType.FACE]);
        }
      },
      handleCurrentChange(val) {
        if(!val){
          return;
        }
        this.params.holeSelectInfo = val;
        this.params.holeIndex = val.holeIndex;
        if(this.editType === 0){
          this.editHoleData();
        }
      },
      buttonDisabled() {
        if (this.params.holeIndex === -1) {
          return true;
        } else {
          return false;
        }
      },
      //新建
      addHoleData() {
        this.params.holeIndex = this.params.installHoleInfoList.length;
        this.params.holeType = 1;

        this.isHoleEdit = true;
        this.editType = 1;

        this.switchQuery("installHolePointList");
      },
      //编辑
      editHoleData() {
        if (!this.params.holeSelectInfo) {
          return;
        }
        this.setHoleInfo(this.params.holeSelectInfo);

        this.isHoleEdit = true;
        this.editType = 0;

        this.switchQuery("installHolePointList");
      },
      setHoleInfo(holeInfo){
        this.params.installHolePointList = [holeInfo.installHolePoint];
        this.params.holeIndex = holeInfo.holeIndex;
        this.params.holeName = holeInfo.holeName;
        this.params.holeSymmetry = holeInfo.holeSymmetry;
        this.params.holeSymmetryName = holeInfo.holeSymmetryName;
        this.params.holeType = holeInfo.holeType;
      },
      //删除
      deleteHoleData() {
        //必须保证有一个孔数据
        if(this.params.installHoleInfoList.length <= 0) {
          return;
        }
        let newGroups = [];
        for(let i = 0;i < this.params.installHoleInfoList.length;i++)
        {
          let curHoleInfo = this.params.installHoleInfoList[i];
          if(i !== this.params.holeIndex){
            if(i > this.params.holeIndex){
              curHoleInfo.holeIndex -= 1;
            }
            newGroups.push(curHoleInfo);
          }
        }

        this.params.installHoleInfoList = newGroups;
        this.editType = -1;
      },
      //保存孔参数
      saveHoleData(){
        if (this.params.installHolePointList.length <= 0) {
          InsulationCoverFrameToolCmd.eventBusAlertMsg("请选择孔定位点！", "warning");
          return;
        }
        let holeSymmetryName;
        if(this.params.holeSymmetry == 0){
          holeSymmetryName = "对称";
        }else if(this.params.holeSymmetry == 1){
          holeSymmetryName = "左侧";
        }else{
          holeSymmetryName = "右侧";
        }
        let tempHoleInfoList = [];
        for(let i = 0;i < this.params.installHolePointList.length;i++)
        {
          let curInstallHolePoint = this.params.installHolePointList[i];
          let holeInfo = {
            installHolePoint:curInstallHolePoint,
            holeIndex:this.params.holeIndex + i,
            holeName:curInstallHolePoint.name,
            holeSymmetryName:holeSymmetryName,
            holeSymmetry:this.params.holeSymmetry,
            holeType:this.params.holeType
          }
          tempHoleInfoList.push(holeInfo);
        }

        for(let n = 0;n < tempHoleInfoList.length;n++){
          let curHoleInfo = tempHoleInfoList[n];
          //判断是否与已有列表内容重复
          let checkRepeat = this.checkRepeat(this.params.installHoleInfoList,curHoleInfo,"installHolePoint",this.params.holeIndex);
          if(checkRepeat){
            InsulationCoverFrameToolCmd.eventBusAlertMsg("安装定位孔重复！", "warning");
            return;
          }

          //如果是添加，将内容添加到列表，编辑直接替换
          if(this.editType === 1){
            this.params.installHoleInfoList.push(tempHoleInfoList[n]);
          }else{
            if(n === 0){
              this.params.installHoleInfoList[this.params.holeIndex] = curHoleInfo;
            }else{
              this.params.installHoleInfoList.push(tempHoleInfoList[n]);
            }
          }
        }

        this.params.installHolePointList = [];

        this.switchQuery("forkLineList");
        this.isHoleEdit = false;
        this.editType = -1;
      },
      cancelHoleData(){
        this.isHoleEdit = false;
        this.editType = -1;
      },
      //检查重复，list中的propName属性中的id,与ele中的propName属性中的id重复返回true，第noCheckNo个可不检查
      checkRepeat(list,ele,propName,noCheckNo){
        let bIsExisted = false;
        if(!ele || !ele[propName] || !ele[propName].id){
          return true;
        }
        for(let i = 0;i < list.length;i++){
          if(!list[i] || !list[i][propName] || !list[i][propName].id){
            return true;
          }

          if(i !== noCheckNo &&ele[propName].id === list[i][propName].id){
            bIsExisted = true;
            break;
          }
        }
        return bIsExisted;
      },

      setCurTab(tab) {
        if (tab.index === "0"){
          //this.params.curTab = this.tabOptions[0];
          this.switchQuery("skins");
        }else if (tab.index === "2"){
          //this.params.curTab = this.tabOptions[2];
        }else if (tab.index === "3"){
          this.switchQuery("forkLineList");
          //this.params.curTab = this.tabOptions[3];
          // this.switchQuery("forkLineList");
        }
      },
      confirm() {
        //当框类型为全高度框时，长桁高度为0
        if(this.params.frameType === 2){
          this.params.stringerHeight = 0;
        }

        InsulationCoverFrameToolCmd.executeConfirm(this.params);
      },
      cancel() {
        InsulationCoverFrameToolCmd.closeActiveCmd();
      },
      //改变航向的选择项
      modifyCourse(plane){
        let planeNormal = plane?.params?.normal;
        if(!planeNormal){
          return;
        }

        let vectDir = new THREE.Vector3(planeNormal.x,planeNormal.y,planeNormal.z);
        vectDir.normalize();
        let xDir = new THREE.Vector3(1,0,0);
        let yDir = new THREE.Vector3(0,1,0);
        let zDir = new THREE.Vector3(0,0,1);

        let dotXValue = vectDir.clone().dot(xDir);
        if(Math.abs(dotXValue) - 0.999 > 0)
        {
          this.params.courseOptions = [{text:"X轴",value:11},{text:"-X轴",value:12}];
          this.params.courseNo = 11;
          return;
        }
        let dotYValue = vectDir.clone().dot(yDir);
        if(Math.abs(dotYValue) - 0.999 > 0)
        {
          this.params.courseOptions = [{text:"Y轴",value:21},{text:"-Y轴",value:22}];
          this.params.courseNo = 21;
          return;
        }
        let dotZValue = vectDir.clone().dot(zDir);
        if(Math.abs(dotZValue) - 0.999 > 0)
        {
          this.params.courseOptions = [{text:"Z轴",value:31},{text:"-Z轴",value:32}];
          this.params.courseNo = 31;
          return;
        }
      },
    },
    watch:{
      "params.frames": function () {
        if(this.params.frames.length === 0){
          this.params.courseOptions = [{text:"X轴",value:11},
            {text:"-X轴",value:12},
            {text:"Y轴",value:21},
            {text:"-Y轴",value:22},
            {text:"Z轴",value:31},
            {text:"-Z轴",value:32}];
        }
      }
    }
  }
</script>
<style scoped>
  .wrap {
    font-size: 12px;
  }
  .label-style {
    font-size: 12px;
    color: #606266;
    line-height: 30px;
  }
  .count-align {
    align-self: flex-end;
  }
  .url-style {
    width: 100%;
    height: 300px;
    display: block;
    margin-top: 10px;
    border: 1px darkgray solid;
  }
  .button-style {
      display: flex;
      justify-content: flex-end;
      margin-top: 5px;
  }
  .operation-border {
       border: 2px solid var(--bg-color3);
       padding: 8px;
   }
</style>